<?php
/**
 * [weliam] Copyright (c) 2016/3/23
 * index.ctrl
 * 全部商品列表控制器
 */
defined('IN_IA') or exit('Access Denied');
$ops = array('door_teacher','door_student');
$op = in_array($_GPC['op'], $ops) ? $_GPC['op'] : '';
global $_W;
if($op =='door_teacher'){
    $info_id = $_POST['info_id'];
    $door = $_POST['door'];
    if($info_id==''|$door==''){
        $prompt = '信息不全，无法更新二维码！';
        include wl_template('tips/prompt');
        exit;        
    }
    $time = time();
    $random = $this->return_random();
    
    $ifexist = pdo_get('homework_door_teacher', array('uniacid' => $_W['uniacid'] , 'device_info_id' => $info_id ,'door' => $door) ,array('random'));
    if($ifexist==null){
        //print_r(111);
        $arr = array('uniacid'=>$_W['uniacid'] ,'time'=>$time ,'random'=>$random ,'device_info_id'=>$info_id ,'door' => $door);
        pdo_insert('homework_door_teacher' , $arr);       
    }
    else{
        $arr = array('time'=>$time ,'random'=>$random);
        pdo_update('homework_door_teacher' , $arr ,array('uniacid'=>$_W['uniacid'] ,'device_info_id'=>$info_id ,'door' => $door));  
    }
    $random = pdo_get('homework_door_teacher', array('uniacid' => $_W['uniacid'] , 'device_info_id' => $info_id ,'door' => $door) ,array('random'));
    print_r($random['random']);
    exit;
}
if($op =='door_student'){
    $info_id = $_POST['info_id'];
    $door = $_POST['door'];
    if($info_id==''|$door==''){
        $prompt = '信息不全，无法更新二维码！';
        include wl_template('tips/prompt');
        exit;        
    }
    $time = time();
    $random = $this->return_random();
    
    $ifexist = pdo_get('homework_door_student', array('uniacid' => $_W['uniacid'] , 'device_info_id' => $info_id ,'door' => $door) ,array('random'));
    if($ifexist==null){
        //print_r(111);
        $arr = array('uniacid'=>$_W['uniacid'] ,'time'=>$time ,'random'=>$random ,'device_info_id'=>$info_id ,'door' => $door);
        pdo_insert('homework_door_student' , $arr);       
    }
    else{
        $arr = array('time'=>$time ,'random'=>$random);
        pdo_update('homework_door_student' , $arr ,array('uniacid'=>$_W['uniacid'] ,'device_info_id'=>$info_id ,'door' => $door));  
    }
    $random = pdo_get('homework_door_student', array('uniacid' => $_W['uniacid'] , 'device_info_id' => $info_id ,'door' => $door) ,array('random'));
    print_r($random['random']);
    exit;
}